package org.gitman.agentplatform.ui.simulation;

import java.awt.Color;
import java.util.ArrayList;
import java.util.Collections;

import javax.swing.table.AbstractTableModel;

import org.gitman.agentplatform.agent.api.Agent;
import org.gitman.agentplatform.agent.api.AgentInfo;
import org.gitman.agentplatform.core.PlatformManager;

public class AgentTableModel extends AbstractTableModel{
	private static String [] columns = {"ID", "", "Name", "Goal", "State"};
	private PlatformManager platformManager;
	
	public AgentTableModel() {
		platformManager = PlatformManager.getInstatnce();
	}
	
	@Override
	public int getRowCount() {
		return platformManager.getSimulation().getAgentManager().getAllAgentsInfo().size();
	}

	@Override
	public int getColumnCount() {
		return columns.length;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		ArrayList<Agent> list =  new ArrayList<Agent>(platformManager.getSimulation().getAgentManager().getAgents());
		Collections.sort(list);
		Agent agent = list.get(rowIndex);
		AgentInfo info = agent.getAgentInfo();
		
		switch (columnIndex) {
		case 0:
			return info.getId();
		case 1:
			return info.getColor();
		case 2:
			return agent.getClass().getSimpleName();
		case 3:
			return info.getEndVertexID();
		case 4: 
			return info.getAgentState();
		default:
			return "###";
		}		
	}
	
	@Override
	public Class<?> getColumnClass(int column) {
		if(column == 1){
			return Color.class;
		}else{
			return String.class;
		}
	}

	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return false;
	}
	
	@Override
	public String getColumnName(int arg0) {
		return columns[arg0];
	}
	
}
